﻿using Caliburn.Micro;
using Wulong.Phone.Dianping.Constants;
using Wulong.Phone.Dianping.Services;
using Wulong.Phone.Dianping.Utils;

namespace Wulong.Phone.Dianping.ViewModels
{
    public class SplashViewModel : Screen
    {
        private readonly INavigationService _navigation;
        public SplashViewModel(
            INavigationService navigation)
        {
            _navigation = navigation;
        }

        protected override void OnViewReady(object view)
        {
            base.OnViewReady(view);
            string cityCode;
            if (AppSettings.TryGetSetting(CommonConstants.MyCityStorageKey, out cityCode))
            {
                var city = DianpingService.GetCity(cityCode);
                _navigation
                    .UriFor<MainViewModel>()
                    .WithParam(x => x.CityCode, city.Code)
                    .WithParam(x => x.CityPinyin, city.Pinyin)
                    .Navigate();
            }
            else
            {
                _navigation
                    .UriFor<YourCityViewModel>()
                    .Navigate();
            }
        }
    }
}
